package com.huangfu.learning.javabase.java.enumeration;

/**
 * Created with IntelliJ IDEA.
 * Author: huangfu.daohui
 * Date: 2018/7/9
 * Time: 19:46
 * Version: 1.0
 * Description: 在枚举中添加方法，属性等.枚举里有属性（例如code等），就必须要有构造函数
 **/
public enum EnumMethod {
    /*定义了7个对象*/
    CODE_200("200", "操作成功！！"),
    CODE_401("401", "未授权"),
    CODE_400("400", "请求错误"),
    CODE_403("403", "服务器拒绝请求"),
    CODE_405("405", "方法禁用"),
    CODE_409("409", "冲突"),
    CODE_500("500", "服务器内部错误");

    /*两个属性*/
    private String code;
    private String msg;

    /*构造函数 必要*/
    EnumMethod(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /*属性的setter和getter*/
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getmsg() {
        return msg;
    }

    public void setmsg(String msg) {
        this.msg = msg;
    }

    public static void main(String[] args) {
        for (EnumMethod enumMethod : EnumMethod.values()) {
            //打印枚举值和参数
            /**
             * name:CODE_200; code:200; msg:操作成功！！
             * name:CODE_401; code:401; msg:未授权
             * name:CODE_400; code:400; msg:请求错误
             * name:CODE_403; code:403; msg:服务器拒绝请求
             * name:CODE_405; code:405; msg:方法禁用
             * name:CODE_409; code:409; msg:冲突
             * name:CODE_500; code:500; msg:服务器内部错误
             */
            System.out.println("name:" + enumMethod.name() + "; code:" + enumMethod.code + "; msg:" + enumMethod.msg);
        }
        System.out.println("============================");
        System.out.println("name:" + EnumMethod.CODE_200.name() + "; code:" + EnumMethod.CODE_200.code + "; msg:" + EnumMethod.CODE_200.msg);

    }

}
